package com.qfedu.edu.seckill.storageservice.controller;


import com.qfedu.edu.seckill.po.StockStorage;
import com.qfedu.edu.seckill.result.R;
import com.qfedu.edu.seckill.storageservice.service.StockStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaobobo
 * @since 2025-01-13
 */
@RestController
@RequestMapping("/storageservice/stock-storage")
public class StockStorageController {

    @Autowired
    private StockStorageService stockStorageService;

    @GetMapping("list")
    @Secured({"ROLE_admin"})  //通过判断角色 判断是否能访问
    @PreAuthorize("hasAnyAuthority('user_add')")
    public R list(){
        List<StockStorage> list = stockStorageService.list(null);
        return R.ok().data("storageList",list);
    }

    /**
     * 添加库存信息到数据库
     * @param classId
     * @param quantity
     * @return
     */
    @PostMapping("addStockStorage")
    public R addStockStorage(String classId,Integer quantity){
        int realQuantity=stockStorageService.addStockStorage(classId,quantity);
        return R.ok().data("quantity",realQuantity);
    }

}

